package com.ruoyi.system;

import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AhhcItems;
import com.ruoyi.system.service.IAhhcItemsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管理端可增删改查Controller
 *
 * @author ruoyi
 * @date 2025-03-14
 */
@RestController
@RequestMapping("/system/items")
public class AhhcItemsController extends BaseController
{
    @Autowired
    private IAhhcItemsService ahhcItemsService;

    /**
     * 查询管理端可增删改查列表
     */
    @PreAuthorize("@ss.hasPermi('system:items:list')")
    @GetMapping("/list")
    public TableDataInfo list(AhhcItems ahhcItems)
    {
        startPage();
        List<AhhcItems> list = ahhcItemsService.selectAhhcItemsList(ahhcItems);
        return getDataTable(list);
    }
    /**
     * 物品类展示
     */
    @GetMapping("/getshow")
    public AjaxResult getItems(){
        List<AhhcItems> list = ahhcItemsService.selectShow();
        return AjaxResult.success(list);
    }

    /**
     * 导出管理端可增删改查列表
     */
    @PreAuthorize("@ss.hasPermi('system:items:export')")
    @Log(title = "管理端可增删改查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AhhcItems ahhcItems)
    {
        List<AhhcItems> list = ahhcItemsService.selectAhhcItemsList(ahhcItems);
        ExcelUtil<AhhcItems> util = new ExcelUtil<AhhcItems>(AhhcItems.class);
        util.exportExcel(response, list, "管理端可增删改查数据");
    }

    /**
     * 获取管理端可增删改查详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:items:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(ahhcItemsService.selectAhhcItemsByCode(code));
    }

    /**
     * 新增管理端可增删改查
     */
    @PreAuthorize("@ss.hasPermi('system:items:add')")
    @Log(title = "管理端可增删改查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AhhcItems ahhcItems)
    {
        ahhcItems.setCode(UUID.randomUUID().toString().replace("-", ""));
        return toAjax(ahhcItemsService.insertAhhcItems(ahhcItems));
    }

    /**
     * 修改管理端可增删改查
     */
    @PreAuthorize("@ss.hasPermi('system:items:edit')")
    @Log(title = "管理端可增删改查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AhhcItems ahhcItems)
    {

        return toAjax(ahhcItemsService.updateAhhcItems(ahhcItems));
    }

    /**
     * 删除管理端可增删改查
     */
    @PreAuthorize("@ss.hasPermi('system:items:remove')")
    @Log(title = "管理端可增删改查", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        return toAjax(ahhcItemsService.deleteAhhcItemsByCodes(codes));
    }
}
